#include <proxy/proxy.h>

#include <iomanip>
#include <iostream>
#include <sstream>


void streaming_example()
{
    // 定义可流式输出的 facade
    struct Streamable : pro::facade_builder ::add_convention<pro::operator_dispatch<"<<", true>, std::ostream&(std::ostream&) const>::build
    {
    };

    // 不同类型的数据
    std::string text = "Streamable string";
    int number = 123;
    double pi = 3.14159;

    pro::proxy<Streamable> p1 = &text;
    pro::proxy<Streamable> p2 = pro::make_proxy<Streamable>(number);
    pro::proxy<Streamable> p3 = pro::make_proxy<Streamable>(pi);

    // 使用流操作符
    std::cout << "Stream output:\n";
    std::cout << "  p1: " << *p1 << "\n";
    std::cout << "  p2: " << *p2 << "\n";
    std::cout << "  p3: " << std::fixed << std::setprecision(2) << *p3 << "\n";

    // 使用 stringstream
    std::ostringstream oss;
    oss << "Combined: " << *p1 << " | " << *p2 << " | " << *p3;
    std::cout << "  " << oss.str() << "\n";
}